<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>资源编辑</title>
		<script type="text/javascript" src="scripts/jquery.min.js"></script>
		<script type="text/javascript" src="scripts/bootstrap.min.js"></script>
		<script type="text/javascript" src="scripts/jquery-1.10.2.min.js"></script>
		<script type="text/javascript" src="scripts/bootstrapValidator.js"></script>
		<link href="styles/bootstrap.min.css" rel="stylesheet" />
		<link href="styles/bootstrapValidator.css" rel="stylesheet" />
		<link rel="stylesheet" href="styles/select2.css">
		<script type="text/javascript" src="scripts/select2.js"></script>
</head>
<body>
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		<h4 class="modal-title" id="myModalLabel">新增资源</h4>
	</div>
	<div class="modal-body">
		<form role="form" class="form-horizontal" method="post" id="resourceForm">
			<div class="form-group">
				<label class="col-sm-3 control-label">名称：</label>
				<div class="col-sm-9">
					<input type="text" name="resource.name" value="${resource.name}" class="form-control" placeholder="请输入资源名称" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">类型：</label>
				<div class="col-sm-9">
					<s:select cssClass="form-control" name="resource.type" value="resource.type" list="#{'button':'按钮','menu':'菜单'}" label="请选择资源类型" listKey="key" listValue="value">
					</s:select>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">URL路径：</label>
				<div class="col-sm-9">
					<input type="text" name="resource.url" value="${resource.url }" class="form-control" placeholder="请输入URL路径" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">权限标识：</label>
				<div class="col-sm-9">
					<input type="text" name="resource.permission" value="${resource.permission }" class="form-control" placeholder="请输入权限标示" />
				</div>
			</div>
			<c:choose>
				<c:when test="${id>0}">
					<c:if test="${!resource.rootNode}">
						<div class="form-group">
							<label class="col-sm-3 control-label">上级菜单：</label>
							<div class="col-sm-9">
								<s:select cssClass="form-control" name="resource.parentId" value="resource.parentId" list="menuList" label="请选择父级菜单" listKey="id" listValue="name">
								</s:select>
							</div>
						</div>
					</c:if>
				</c:when>
				<c:otherwise>
					<div class="form-group">
						<label class="col-sm-3 control-label">父级菜单：</label>
						<div class="col-sm-9">
							<s:select cssClass="form-control" name="resource.parentId" value="pid" headerKey="0" headerValue="无" list="menuList" label="请选择父级菜单" listKey="id" listValue="name">
							</s:select>
						</div>
					</div>
				</c:otherwise>
			</c:choose>

		</form>
	</div>
	<div class="modal-footer">
		<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
		<button type="button" class="btn btn-primary" onclick="submit()">提交</button>
	</div>

	<script type="text/javascript">
		function submit() {
			if ("${id}" > 0) {
				document.forms[0].action = "resourceAction!update.action";
			} else {
				document.forms[0].action = "resourceAction!create.action";
			}

			document.forms[0].submit();
		};
		
		$(function(){
			if('${id}'>0){
				$("#myModalLabel").text("修改资源");
			}
		});
	</script>
	
		<script type="text/javascript">
	
	$(document).ready(function() {
	    $('#resourceForm').bootstrapValidator({
	        message: 'This value is not valid',
	        feedbackIcons: {
	            valid: 'glyphicon glyphicon-ok',
	            invalid: 'glyphicon glyphicon-remove',
	            validating: 'glyphicon glyphicon-refresh'
	        },
	        fields: {
	            "resource.name": {
	                message: 'The username is not valid',
	                validators: {
	                    notEmpty: {
	                        message: '资源名不能为空'
	                    }
	        		}
	            }
	        }
	        });
	});
	</script>

</body>
</html>